const process = require('process')
const fs = require('fs')
const args = process.argv.splice(2)

function deleteFolder(path) {
  let files = [];
  if( fs.existsSync(path) ) {
    files = fs.readdirSync(path);
    files.forEach(function(file,index){
      let curPath = path + "/" + file;
      if(fs.statSync(curPath).isDirectory()) {
          deleteFolder(curPath);
      } else {
          fs.unlinkSync(curPath);
      }
    })
    fs.rmdirSync(path);
  }
}

if(args && args.length) {
  args.forEach(function (path) {

    if(fs.existsSync(path)) {
      let stat = fs.statSync(path)

      if (stat.isFile()) {
        fs.unlink(path)
        console.log(`delete ${path}`)
      }

      if (stat.isDirectory()) {
        deleteFolder(path)
        console.log(`delete ${path}`)
      }
    } else {
      console.log(`${path} does not exist`)
    }
  })
}
